﻿/*****************************************************************//**
 * @file    FITKGraphObjectSpringPoint2Point.h
 * @brief   Graph object for point to point spring.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-06-20
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTSPRINGPOINT2POINT_H__
#define __FITKGRAPHOBJECTSPRINGPOINT2POINT_H__

#include "FITKGraphObjectMarkBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkPoints;
class vtkCellArray;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkSelectionNode;
class vtkSelection;
class vtkExtractSelection;
class vtkIdTypeArray;
class vtkIntArray;
class vtkCell;
class vtkSphereSource;
class vtkGlyph3D;
class vtkStringArray;
class vtkTextProperty;
class vtkDistanceToCamera;
class vtkSelectVisiblePoints;
class vtkPointSetToLabelHierarchy;

class FITKGraphActor;
class FITKGraphActor2D;

namespace Interface
{
    class FITKAbaSpringDashpotPoint2Point;
    class FITKBoundaryLocation;
}

namespace Exchange
{
    /**
     * @brief   Graph object for point to point spring.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-20
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectSpringPoint2Point : public FITKGraphObjectMarkBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectSpringPoint2Point, FITKGraphObjectMarkBase);
        FITKCLASS(Exchange, FITKGraphObjectSpringPoint2Point);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   springData: The spring data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        FITKGraphObjectSpringPoint2Point(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaSpringDashpotPoint2Point* springData);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        virtual ~FITKGraphObjectSpringPoint2Point();

        /**
         * @brief   Show or hide graph object.[override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Highlight the spring graph actors.[override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the spring graph actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void disHighlight() override;

        /**
         * @brief   Highlight part of the spring graph object by the given id of spring pair.[override]
         * @param   details: The details about highlighting.( The id of the spring pair need to be highlighted. )[default]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void advanceHighlight(QVariant details, QColor color = QColor()) override;

        /**
         * @brief   Dis-advance highlight.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void disAdvanceHighlight() override;

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void updateVisibility() override;

        /**
         * @brief   Simplified the graph object if necessary.[override]
         * @param   enabled: Enabled simplified flag
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void simplified(bool enabled) override;

        /**
         * @brief   If the graph object has relation with the given data object id.[override]
         * @param   dataObjId: The data object id
         * @return  Has relation
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        bool isRelatedTo(int dataObjId) override;

        /**
         * @brief   Set the render, which will add this graph object to itself.( for calculating size )[override]
         * @param   render: The FITKGrapgRender
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void setFITKRender(Comp::FITKGraphRender* render) override;

    private:
        /**
         * @brief   Initialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void init();

        /**
         * @brief   Reset the advance data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void clearAdvanceData();

        /**
         * @brief   Initialize the actors.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void initActors();

        /**
         * @brief   Generate the actors for glyph, line and label.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void generateActors();

        /**
         * @brief   Generate the actors for glyph, line and label for advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void generateActorsAdvance();

        /**
         * @brief   Clear the model ids and the visibility hash.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void clearModelsInfo() override;

        /**
         * @brief   Clear the data.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void clearData() override;

        /**
         * @brief   Generate spring actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        void generateGraph() override;

        /**
         * @brief   Generate the poly data for the spring.
         * @param   springData: The spring data object
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        bool generatePolyData(Interface::FITKAbaSpringDashpotPoint2Point* springData);

        /**
         * @brief   Enable or disable visible points filter.
         * @param   enabled: Is enable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        void enableVisiblePoints(bool enabled);

    private:
        // For labels.
        //@{
        /**
         * @brief   The label font size.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        double m_fontSize = 18.;

        /**
         * @brief   The label text property.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkTextProperty* m_textProperty{ nullptr };

        /**
         * @brief   The points data for labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkPoints* m_pointsText{ nullptr };

        /**
         * @brief   The string array stored the text of labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkStringArray* m_textArray{ nullptr };

        /**
         * @brief   The poly data for label text.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkUnstructuredGrid* m_ugridText{ nullptr };

        /**
         * @brief   The actor 2D for label text.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        FITKGraphActor2D* m_fActorText2D{ nullptr };

        /**
         * @brief   The selection node for extract mesh grid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkSelectionNode* m_selectNodeText{ nullptr };

        /**
         * @brief   The selection for vtkSelectionNode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkSelection* m_sectionText{ nullptr };

        /**
         * @brief   The mesh grid extractor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkExtractSelection* m_extractSelectionText{ nullptr };

        /**
         * @brief   The filter for hiding the label text for invisible points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-24
         */
        vtkSelectVisiblePoints* m_visiblePointsText{ nullptr };

        ///**
        // * @brief   The indice array of extract id.
        // * @author  ChengHaotian (yeguangbaozi@foxmail.com)
        // * @date    2024-06-20
        // */
        //vtkIdTypeArray* m_idArrayText{ nullptr };
        //@}

        // For glyphs and lines.
        //@{
        /**
         * @brief   The glyph sphere source.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkSphereSource* m_sphereSource{ nullptr };

        /**
         * @brief   The glyph size of the spring shape.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        double m_glyphSize = 20.;

        /**
         * @brief   The points data for spring glyphs.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkPoints* m_points{ nullptr };

        /**
         * @brief   The fixed-size filter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkDistanceToCamera* m_distanceToCamera{ nullptr };

        /**
         * @brief   The glyph filter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkGlyph3D* m_glyph{ nullptr };

        /**
         * @brief   The grid data for spring glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkUnstructuredGrid* m_ugrid{ nullptr };

        /**
         * @brief   The graph actor for spring glyphs.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        FITKGraphActor* m_fActor{ nullptr };

        /**
         * @brief   The selection node for extract mesh grid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkSelectionNode* m_selectNode{ nullptr };

        /**
         * @brief   The selection for vtkSelectionNode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkSelection* m_section{ nullptr };

        /**
         * @brief   The mesh grid extractor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkExtractSelection* m_extractSelection{ nullptr };

        /**
         * @brief   The indice array of extract id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkIdTypeArray* m_idArray{ nullptr };
        //@}

        // For lines.
        //@{
        /**
         * @brief   The graph actor for spring lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        FITKGraphActor* m_fActorLine{ nullptr };
        //@}

        // For advanced highlight.
        //@{
        /**
         * @brief   The points data for spring glyphs in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkPoints* m_pointsAdv{ nullptr };

        /**
         * @brief   The fixed-size filter in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkDistanceToCamera* m_distanceToCameraAdv{ nullptr };

        /**
         * @brief   The glyph filter in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkGlyph3D* m_glyphAdv{ nullptr };

        /**
         * @brief   The grid data for spring in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkUnstructuredGrid* m_ugridAdv{ nullptr };

        /**
         * @brief   The graph actor for spring glyphs in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphActor* m_fActorAdv{ nullptr };

        /**
         * @brief   The graph actor for spring lines in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphActor* m_fActorLineAdv{ nullptr };

        /**
         * @brief   The label text hierarchy.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-08
         */
        vtkPointSetToLabelHierarchy* m_labelHieText{ nullptr };

        /**
         * @brief   The points data for labels in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkPoints* m_pointsTextAdv{ nullptr };

        /**
         * @brief   The string array stored the text of labels in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkStringArray* m_textArrayAdv{ nullptr };

        /**
         * @brief   The poly data for label text in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkUnstructuredGrid* m_ugridTextAdv{ nullptr };

        /**
         * @brief   The actor 2D for label text in advance highlight mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphActor2D* m_fActorText2DAdv{ nullptr };
        //@}

        /**
         * @brief   The model id data array.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        vtkIntArray* m_modelIdArray{ nullptr };

        /**
         * @brief   All model ids for surface of the graph object.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        QList<int> m_modelIds;

        /**
         * @brief   The visibility of all components' parent models.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        QHash<int, bool> m_modelVisibilityHash;

        /**
         * @brief   Saved model id and node id pair list.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        QList<QPair<int, int>> m_lastModelIdNodeIdHash;

        /**
         * @brief   Use the coefficient.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        bool m_useCoeff = false;

        /**
         * @brief   Use the stiffness.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        bool m_useStiff = false;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTSPRINGPOINT2POINT_H__
